﻿namespace BJYJ_Admin.Application.System.Services
{
    public class UserService : IDynamicApiController, ITransient
    {
        public readonly IRepository<System_Users> _userRepository;
        public UserService(IRepository<System_Users> userRepository)
        {
            _userRepository = userRepository;
        }

        /// <summary>
        /// 登陆接口允许匿名访问  
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [AllowAnonymous]
        public async Task<UserOutDto> Login(UserInputDto user)
        {
            var result = await _userRepository.FindOrDefaultAsync((System_Users a) => a.UserName == user.UserName);
            return result != null ? new UserOutDto { /* map properties from result */ } : null;
        }
        /// <summary>
        /// 判断Jwt的用户名和密码是否和当前数据库的匹配，避免其他系统的Jwt可调用
        /// </summary>
        /// <param name="UserName">用户名</param>
        /// <param name="PassWord">密码</param>
        /// <returns></returns>
        public bool ValidateCredentials(string UserName, string PassWord)
        {
            return _userRepository.Where(u => u.UserName == UserName && u.PassWd == PassWord).Any();
        }
    }
}
